package com.example.viewpageapplication.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.viewpageapplication.R;
import com.example.viewpageapplication.entity.BaseT;

import java.util.List;

public class BaseVadapter extends BaseAdapter {

    private List<BaseT> baseTList;
    private Context mcontext;
    public BaseVadapter(Context context, List<BaseT> baseTList) {
        this.mcontext = context;
        this.baseTList = baseTList;
    }

    @Override
    public int getCount() {
        return baseTList.size();
    }

    @Override
    public Object getItem(int position) {
        return baseTList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Viewhoder viewhoder;
        if(convertView == null){
            viewhoder = new Viewhoder();
            convertView = LayoutInflater.from(mcontext).inflate(R.layout.base_lv_item,null);
            viewhoder.imageView = convertView.findViewById(R.id.item_image);
            viewhoder.textView = convertView.findViewById(R.id.item_tv);
            convertView.setTag(viewhoder);
        }else {
            viewhoder = (Viewhoder) convertView.getTag();
        }
        BaseT baseT = baseTList.get(position);
        viewhoder.imageView.setImageResource(baseT.imagId);
        viewhoder.textView.setText(baseT.message);
        return convertView;
    }

  public class Viewhoder {
        ImageView imageView;
        TextView textView;
    }
}
